<?php

namespace app\admin\model\yalimedia;

use think\Model;
use  app\admin\model\yalimedia\course\Category;

class Course extends Model
{
    // 表名
    protected $name = 'yalimedia_course';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = "int";

    // 定义时间戳字段名
    protected $createTime = "createtime";
    protected $updateTime = false;


    public function getList($where,$page,$limit){
        $courseModel = new self();
        $total = $courseModel
            ->where($where)
            ->count();

        $courseModel = new self();
        $data = $courseModel
            ->where($where)
            ->page($page,$limit)
            ->select();

        foreach($data as &$v){
            $v['course_count'] = CourseContent::get_content_num($v['id']);
        }

        return ['total'=>$total,'data'=>$data];
    }


}
